# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: rubicon <rubicon@mailo.com>
pkgname=rakudo-star
pkgver=2022.04
pkgrel=0
pkgdesc="Batteries included modules bundle for the Raku programming language"
url="https://rakudo.org/star/"
# riscv64 blocked by moarvm
arch="all !s390x !riscv64"
license="Artistic-2.0"
depends="rakudo>$pkgver readline libssl1.1"
makedepends="bash perl-utils zef"
checkdepends="perl-test-harness cmd:aspell"
options="!check"	# some tests fail
subpackages="$pkgname-doc"
source="https://github.com/rakudo/star/releases/download/$pkgver/rakudo-star-$pkgver.tar.gz
	use-system-raku.patch
	install-to-rstar_prefix.patch
	fix-testing-with-prove6.patch
	fix-rakudoc-directory.patch
	openssl-libs-version.patch
	openssl-remove-windlls.patch
	"
builddir="$srcdir/$pkgname-$pkgver"
_modsdir="$builddir"/src/rakudo-star-modules

prepare() {
	default_prepare

	# We have zef as a separate package
	sed -i 's/^zef/#zef/' etc/modules.txt

	# DBIish isn't included in the tarball for now
	if [ ! -d "$_modsdir"/DBIish ]; then
		sed -i 's/^DBIish/#DBIish/' etc/modules.txt
	fi

	# NativeHelpers-Blob fails to build on 32-bit platforms
	case $CARCH in
	arm*|x86)
		sed -i 's/^NativeHelpers/#NativeHelpers/' etc/modules.txt
		;;
	esac
}

build() {
	# File-Find for rakudoc, Perl6-PathTools and JSON-Fast for OpenSSL
	# Note that the path separator is a comma not a colon
	export RAKULIB="$_modsdir"/File-Find,"$_modsdir"/Perl6-PathTools,"$_modsdir"/JSON-Fast

	mkdir -vp "$builddir"/prefix
	ln -sv /usr/share/rakudo/core "$builddir"/prefix/
	find "$_modsdir" -type f -name '*.dll' -delete

	./bin/rstar install -p "$builddir"/prefix modules
}

check() {
	./bin/rstar test -p "$builddir"/prefix modules
}

package() {
	rm -v "$builddir"/prefix/core		# delete symlink
	mkdir -vp "$pkgdir"/usr/share/doc "$pkgdir"/usr/bin
	mv -v "$builddir"/prefix "$pkgdir"/usr/share/rakudo
	rm -v "$pkgdir"/usr/share/rakudo/vendor/version

	ln -sv	/usr/share/rakudo/vendor/bin/prove6 \
		/usr/share/rakudo/vendor/bin/pod2onepage \
		"$pkgdir"/usr/bin/

	mv -v	"$pkgdir"/usr/share/rakudo/site/doc \
		"$pkgdir"/usr/share/doc/"$pkgname"
}

doc() {
	default_doc

	mkdir -vp "$subpkgdir"/usr/share/rakudo/site
	ln -sv /usr/share/doc/"$pkgname" \
		"$subpkgdir"/usr/share/rakudo/site/doc
}

sha512sums="
fb1bf87d578a3eb5b51e683604f551298b82f4efcc031ff3820d77ce6319ca7fc4a805fbfe32b2d85d64659b4bd9a979b78fdd59354008ca156fb8bce652595e  rakudo-star-2022.04.tar.gz
161ea44b57c823a67c6fa5a35c90a89b1a60512439b5323fbfc7f80a29785cc55027c2257d77b4e36bfd42f1c2f6c9142a2f8330350f6777a653ad5a63a45a0a  use-system-raku.patch
d27a50a92cbf857f6de96ff4f2783e22b767f8499644a5554c2dd54b0b023645727ad4d9b491f8de7fe0924b91524a2dbcdad4f5df2c0aa75fd589a5162ea7d9  install-to-rstar_prefix.patch
a33f9471fe762ba05464082abd2513dec9329cb46cc14ae6fd6cd510b4dc2aa8046d64544edd27e45b374b245a91dff8ead333e3ba5ab3a7ab685b508c9637db  fix-testing-with-prove6.patch
331a4515a6485b37875c7fa877df52bab7493ccf703d84efb1bbcb846e63332c6839ac80446b142804300467d037bfb0bddfb45f4e1fb742a6af00cb343d9db3  fix-rakudoc-directory.patch
cc94469a830c5476e6453c215172e7d20672da5b41706a09ed46deaee6b4e3d8ae07fbaed366840e9712afe3ee3503f46fce2bcc459a2fb7734b4acf0baab7ce  openssl-libs-version.patch
2f0376b74dfa5a1ae111f045cfceffce19d6bb087ee4428c2e1bcee0d02b91385b1755b36e10ae16a28333ca73347677e8ee1763bfedd731c5025f53fa0bad6f  openssl-remove-windlls.patch
"
